#@weiXinLayout("特产商城")

#define weiXinMain()
<div class="swiper-container">
    <div class="swiper-wrapper">
        #for(x:pics)
        <div class="swiper-slide">
            <a href="#(x.url??'')">
            <img class="slide-item" src="#(x.cover??'')" alt="">
            </a>
        </div>
        #end
    </div>
    <div class="swiper-pagination"></div>
</div>
<div class="weui-panel weui-panel_access" style="margin-top: 0px;">

    <div class="weui-panel__bd" id="content">
    </div>
    <div class="weui-loadmore">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">正在加载</span>
    </div>
</div>
#include("../../front/common/wx-tab-bar.html")
#end

#define weiXinCss()
<style>
    .price{
        font-weight: bolder;
        font-size:18px ;
        color: #e2541f;
    }
</style>
#end

#define weiXinJs()
<script type="text/x-mustache" id="template">

    {{#items.list}}
        <a href="javascript:void(0);" data-id="{{id}}"  class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__hd">
                    <img class="weui-media-box__thumb" width="70"  src="{{cover}}">
                </div>
                <div class="weui-media-box__bd">
                    <h4 class="weui-media-box__title">{{name}}</h4>
                    <p class="weui-media-box__desc">{{desc}}</p>
                   <p class="weui-media-box__desc"><span class="price">￥{{price}}</span><span class="status">{{is_post}}</span></p>
                </div>
            </a>
    {{/items.list}}
</script>
<script>
    $(document).ready(function(){

        var pageNum = 1;
        var totalPage =1;
        $(document.body).infinite(50);
        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            pageNum =pageNum+1;
            if(pageNum<=totalPage){
                initData(pageNum);
            }else{
                $.toast("加载完毕...")
            }
        });

        $(".swiper-container").swiper({
            loop: true,
            autoplay: 3000,
        });

        function initData(pageNum) {
            var config = {
                "url": "#(contextPath)/weixin/product/ajaxProduct",
                "data": {pageNum:pageNum},
                "successCallBack": function (resp) {
                    var temp = $("#template").html();
                    var content = Mustache.render(temp, {items: resp.data});
                    $("#content").append(content);
                    loading = false;
                    totalPage = resp.data.totalPage
                }
            }
            var ajax = new AjaxUtils(config);
            ajax.executeRequest();
        }

        $("#content").on('click','.weui-media-box',function(){
            var id =$(this).attr("data-id");
            window.location.href="#(contextPath)/weixin/product/shopDetail?id="+id;
        });
        initData(pageNum);
    })
</script>
#end